# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
import pandas as pd

class UniversityPipeline:
    def open_spider(self, spider):
        self.data = []

    def process_item(self, item, spider):
        self.data.append((item.get('name'), item.get('city'), item.get('department'),
                          item.get('level'), item.get('first_rate'), item.get('graduate'), item.get('satisfaction'),
                          item.get('address'), item.get('offweb'), item.get('recweb'), item.get('phone'),
                          item.get('img')
                          ))
        return item

    def close_spider(self, spider):
        data = pd.DataFrame(self.data, columns=['院校名称', '院校所在地', '教育行政主管部门',
                                                '学历层次', '“双一流”建设高校', '研究生院', '满意度',
                                                '详细地址', '官方网址', '招生网址', '官方电话', '图片'])
        data.to_excel('院校.xlsx')
